package com.company;

import java.util.*;

/**
 * @author Administrator
 */
public class HJ8合并表记录 {

    public static void main(String[] args) {

        Map<Integer, Integer> map = new TreeMap<>();
        Scanner scanner = new Scanner(System.in);
        int input = scanner.nextInt();

        for (int i = 0; i < input; i++) {
            int key = scanner.nextInt();
            int value = scanner.nextInt();
            if (map.containsKey(key)){
                map.put(key ,map.get(key) + value);
            }else {
                map.put(key, value);
            }
        }

        for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
            System.out.println(entry.getKey() +" "+ entry.getValue());
        }
    }
}
